package leetcode.editor.cn;

//Java：反转字符串 II
public class ReverseStringIi {
    public static void main(String[] args) {
        Solution solution = new ReverseStringIi().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public String reverseStr(String s, int k) {
            char[] charArray = s.toCharArray();
            for (int i = 0; i < charArray.length; i += 2 * k) {
                int left = i;
                int right = Math.min(charArray.length - 1, left + k - 1);
                while (left <= right) {
                    char temp = charArray[right];
                    charArray[right] = charArray[left];
                    charArray[left] = temp;
                    left++;
                    right--;
                }
            }
            return new String(charArray);
        }

    }
//leetcode submit region end(Prohibit modification and deletion)

}